package com.shujia.wyh;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class RedisAPIDemo1 {
    public static void main(String[] args) {

        //集群的方式连接redis
//        Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
//        jedisClusterNode.add(new HostAndPort("192.168.169.100",7000));
//        jedisClusterNode.add(new HostAndPort("192.168.169.100",7001));
//        jedisClusterNode.add(new HostAndPort("192.168.169.100",7002));
//        jedisClusterNode.add(new HostAndPort("192.168.169.100",7003));
//        jedisClusterNode.add(new HostAndPort("192.168.169.100",7004));
//        jedisClusterNode.add(new HostAndPort("192.168.169.100",7005));
//        jedisClusterNode.add(new HostAndPort("192.168.169.100",7006));
//
//        JedisCluster jedisCluster = new JedisCluster(jedisClusterNode);
//
//        String name = jedisCluster.get("name");
//        System.out.println(name);
//
//        String age = jedisCluster.set("age", "18");
//        String age1 = jedisCluster.get("age");
//        System.out.println(age1);
//
//        String num = jedisCluster.set("num", "Ae23f");
//        jedisCluster.expire("num",10);

        //连接单个redis服务
        //Jedis(String host, int port)
        Jedis jedis = new Jedis("192.168.169.100", 7201);
//        System.out.println(jedis);

        //选择数据库 0-15
        jedis.select(1);

//        //设置字符串值
//        String set = jedis.set("num", "asdRwe5");
//
//        //获取所有的key
//        Set<String> keys = jedis.keys("*");
//        for (String key : keys) {
//            //根据key获取value值
//            String value = jedis.get(key);
//            System.out.println(key + "---" + value);
//        }


        HashMap<String, String> map = new HashMap<>();
        map.put("name","xiaohu");
        map.put("age","18");
        map.put("content","数加科技");
        map.put("address","安徽省合肥市");
        jedis.hset("1001",map);


    }
}
